#ifndef OA_CORE_SYSTEM_H
#define OA_CORE_SYSTEM_H

#include "core/event.h"
#include "core/log.h"
#include "core/task.h"
#include "util.h"
#include "libs.h"

namespace core {
	class Engine;

	class _OA_export System:
		public util::Named
	{
	public:
		friend class Engine;

		struct SystemInitializing {
			SystemInitializing(System* system);
			System* mSystem;
		};

		struct SystemShuttingDown {
			SystemShuttingDown(System* system);
			System* mSystem;
		};

		struct SystemUpdater: public Task {
			SystemUpdater(System* s, unsigned int taskFlags);

			virtual void run();

			System* mSystem;
		};

		System(const std::string& name, unsigned int taskFlags = Task::NONE);
		virtual ~System();

		virtual bool init();
		virtual void update();
		virtual void shutdown();

		template<typename T>
		void addSetting(const std::string& name_in_configfile, T* the_variable);

	protected:
		boost::shared_ptr<SystemUpdater> mSystemUpdater;
		boost::program_options::options_description mSettings;
		Logger mLog;
		EventChannel mChan;
	};

	template <typename T>
	void System::addSetting(const std::string& name, T* var) {
		std::stringstream sstr;
		sstr << getName() << "." << name;

		mSettings.add_options()
			(sstr.str().c_str(), boost::program_options::value<T>(var))
		;
	}
}

#endif
